@layout("/common/_curd/_container.html"){

<script type="text/javascript">
	var ctx = "${basePath}";
	var grid_selector = "#grid-table";
	var pager_selector = "#grid-pager";
	
	$(function(){
		initGrid();
		initMenuBtn("btns", "${code}");
	});
	
	function initGrid(){
		var grid_url = ctx + "/${code}/list";
		var _colnames = ["ID", 
						"姓名",
						"校讯通",
						"电话号码", 
						"职位",
                        "操作"];
		var _colmodel = [{name:"id", index:"id", width:100,hidden:true},
						{name:"name", index:"name", width:100},
						{name:"last_code", index:"last_code",formatter:fmatterReg, width:100},
						{name:"mobile", index:"mobile", width:100},
						{name:"position", index:"position", width:100},
                        {name: 'id',formatter:fmatterOperation, width:200,sortable:false}
        ];
		
		jQuery(grid_selector).jqGrid({
			url : grid_url,
		    shrinkToFit : true,
			colNames : _colnames,
			colModel : _colmodel, 
			jsonReader : {id :"id"},
			pager : pager_selector,
			postData : {sort : "id", order : "desc"}
		});
	}
	function fmatterReg(cellvalue, options, rowObject){
        if (cellvalue){
            return '<span class="label label-sm label-success">已注册</span>';
        }else{
            return '<span class="label label-sm label-warning">未注册</span>';
        }
    }

    function fmatterOperation(cellvalue, options, rowObject){
        return '<button class="btn btn-primary btn-sm" onclick="chooseDept('+cellvalue+',\''+rowObject.depts+'\')">分配部门</button>';
    }

    function chooseDept(id,depts){
        new teacher_tree(
                {
                    'id' : id,
                    'title' : '分配部门',
                    'check_type' : 'checkbox',
                    'callback' : 'deptCallback',
                    'value' : depts.substring(1,depts.length-1),
                    'intercept':'0'
                }
        ).choose();
    }
    function deptCallback(id,ids,names){
        console.log(id+"-"+ids+"-"+names);
        var ajax = new $ax(ctx + "/${code}/chooseDept", function(data){
            if (data.code === 0) {
                layer.msg(data.message, {shift: 1});
                reloadGrid();
                return false;
            } else {
                layer.msg(data.message, {shift: 6});
                return false;
            }
        });
        ajax.data = {"id":id,"ids":ids};
        ajax.start();
    }
</script>


	<!-- 配置 grid -->
	<div class="row">
		<div class="col-xs-12 tb-grid">
			<!-- 配置 查询 -->
			@ var _col=[
			@		{name:"姓名", index:"name", type:"text"},
			@		{name:"电话号码", index:"mobile", type:"text"}
			@];
			@ include("/common/_function/_search2.html",{"col":_col}){}
			<!-- 按钮 -->
			<div class="welljq well-sm" id="btns"></div>
			<!-- grid -->
			<table id="grid-table"></table>
			<!-- 分页-->
			<div id="grid-pager"></div>
		</div>
	</div>
	
	<!-- 引入所需的js -->
	@include("/common/_listscript.html"){}
<script src="${basePath}/static/biz/teacher_tree.js" type="text/javascript" ></script>

@}	